package com.ext.aic.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.ext.aic.R;
import com.ext.aic.adapter.binder.IndustryEnterpriseListItemBinder;
import com.ext.aic.beans.CompanyItem;
import com.ext.aic.databinding.IndustryEnterpriseListItemViewBinding;
import com.ext.aic.holder.IndustryEnterpriseListViewHolder;

import java.util.ArrayList;
import java.util.List;

import lombok.Setter;

public class IndustryEnterpriseListAdapter extends RecyclerView.Adapter<IndustryEnterpriseListViewHolder> {

    @Setter
    private List<CompanyItem> items = new ArrayList<>();
    private IndustryEnterpriseListItemBinder binder;

    public IndustryEnterpriseListAdapter(Context context) {
        this.binder = new IndustryEnterpriseListItemBinder(context);
    }

    @Override
    public IndustryEnterpriseListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.industry_enterprise_list_item_view, parent, false);
        return new IndustryEnterpriseListViewHolder(IndustryEnterpriseListItemViewBinding.bind(view));
    }

    @Override
    public void onBindViewHolder(IndustryEnterpriseListViewHolder holder, int position) {
        CompanyItem companyItem = items.get(position);
        binder.bind(holder, companyItem, position);
    }

    @Override
    public int getItemCount() {
        return items.size();
    }
}
